package com.example.itemdecoration;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<itemBean> fruitList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initData();
        RecyclerView rv = findViewById(R.id.main_recycler_view);
        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.addItemDecoration(new fruitDecoration(this)); // 设置自定义的ItemDecoratin
        rv.setAdapter(new fruitAdapter(this, fruitList));

    }


    private void initData(){
        fruitList = new ArrayList<>();

        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 20; j++) {
                if(i % 2 == 0){
                    fruitList.add(new itemBean("apple" + j, "HL" + i));
                }else {
                    fruitList.add(new itemBean("banana" + j, "HYM" + i));
                }
            }
        }
    }
}